package com.haizhi.crm.search.model;

import lombok.Data;

import java.util.*;

/**
 * Created by chengmo on 2018/5/17.
 */
@Data
public class SearchReq {

    private String domain;
    private String accessToken;
    private String version;

    private String graph;
    private String keyword;
    private int pageNo = 1;
    private int pageSize = 10;
    private Set<String> schemas;
    private Map<String, Object> option;
    private List<Map<String, Object>> query;
    private List<Map<String, Object>> filter;
    private List<Map<String, Object>> sort;
    private List<Map<String, Object>> aggregation;
    private List<String> fields;

    public SearchReq() {
        this.schemas = new HashSet<>();
        this.option = new HashMap<>();
        this.query = new ArrayList<>();
        this.filter = new ArrayList<>();
        this.sort = new ArrayList<>();
        this.aggregation = new ArrayList<>();
        this.fields = new ArrayList<>();
    }

    public void addSchema(String schema) {
        if (this.schemas == null) {
            this.schemas = new HashSet<>();
        }
        this.schemas.add(schema);
    }

    public void clearAndAddSchema(String schema) {
        if (this.schemas == null) {
            this.schemas = new HashSet<>();
        }
        this.schemas.clear();
        this.schemas.add(schema);
    }

    public void addFilter(Map item) {
        if (this.filter == null) {
            this.filter = new ArrayList<>();
        }
        this.filter.add(item);
    }
}
